<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$this->add_member();
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$basic=$this->plugin_setting('basic');
$return['banner']=$basic['image'];
$return['basic']=$basic;
$member=pdo_get('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_SESSION['uid']));
if($_RQ['op']=='main'){
	$id=intval($_RQ['pid']);
	if($id){
		$post=pdo_get('jy_51job_job',array('id'=>$id));
		$post['images']=json_decode($post['images'],true);
		$post['lat_lng']=json_decode($post['lat_lng'],true);
		$type=$post['type'];
		$return['isid']=1;
		$post['pcd']=array('province'=>$post['province'],'city'=>$post['city'],'district'=>$post['district']);

	}else{
		$type=intval($_RQ['type']);
		$post=array('type'=>$type,'isshow'=>1,'realname'=>$member['nickname'],'age'=>18,'sex'=>'女','type_id'=>$_RQ['typeid']);
		$post['pcd']=$this->session('pcd');
		$post['lat_lng']=array('lat'=>'','lng'=>'');
	}
	$typetitle=$type?'求职':'招聘';
	set_html('title','发布'.$typetitle);
	//是否关注
	$return['isfollow']=pdo_getcolumn('core_fans',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'follow');
	if($_RQ['postdata']){
		$postdata=get_postdata();
		$isfabunums = pdo_count('jy_51job_job',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	//	if($setting['maxfabu'] >0 && ($isfabunums >= $setting['maxfabu'])){
	//		exi('已达该活动的发布上限！','error');
	//	}
		if(!$postdata['title']){
			exi('标题不能为空！','error');
		}
		if(!$postdata['remark']){
			exi('说明不能为空！','error');
		}
		
		if(!$postdata['images']){
			//exi('图片不能为空！','error');
		}

		if(!$postdata['name']){
			exi('联系人姓名不能为空！','error');
		}

		if(!$postdata['sex']){
			//exi('请选择性别！','error');
		}
		if(empty($postdata['lat_lng'])){
			exi('请选择坐标！','error');
		}
		if(empty($postdata['mobile'])){
			exi('请填写联系人电话！','error');
		}
		//判断字段必填
		if(!empty($postdata['diyfileds'])){
			foreach($postdata['diyfileds'] as $item){
				if($item['is_must'] && empty($item['data'])){
					exi('请填写:'.$item['title'],'error');
				}
			}
		}
		if($postdata['pcd']){
			$address=$postdata['pcd']['province'].' '.$postdata['pcd']['city'];
			$code=pdo_getcolumn('core_area',array('address'=>$address),'parent_code');
		}
		$insert=array(
			'type'=>$postdata['type_id'],
			'title'=>$postdata['title'],
			'name'=>$postdata['name'],
			'code'=>$code,
			'province'=>$postdata['pcd']['province'],
			'city'=>$postdata['pcd']['city'],
			'district'=>$postdata['pcd']['district'],
			'address'=>$postdata['address'],
			'mobile'=>$postdata['mobile'],
			'weixin'=>$postdata['weixin'],
			'age'=>$postdata['age'],
			'sex'=>$postdata['sex'],
			'timesid'=>$postdata['timesid'],
			'pay'=>$postdata['pay'],
			'educationid'=>$postdata['educationid'],
			'school'=>$postdata['school'],
		//	'status'=>$status,
			'remark'=>$postdata['remark'],
			'images'=>ijson_encode($postdata['images']),
			'lat_lng'=>ijson_encode($postdata['lat_lng']),
			'diyfileds'=>ijson_encode($postdata['diyfileds']),
		);
		if($postdata['id']){
			pdo_update('jy_51job_job',$insert,array('id'=>$postdata['id'],'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
			exi('修改成功','success','jy_51job/myitem/main');
		}else{
			//判断是否需要付费
			$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
			$count=pdo_count('jy_51job_job',array('createtime'=>$daytime,'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
			$insert['createtime']=TIMESTAMP;
			$insert['uniacid']=$_SESSION['uniacid'];
			$insert['mid']=$_SESSION['uid'];
			$msg='发布成功';
			if($basic['item_shenhe']){
				$insert['status']=0;
				$msg='发布成功,等待审核！';
			}else{
				$insert['status']=1;
			}
			pdo_insert('jy_51job_job',$insert);
			$id=pdo_insertid();
			exi($msg,'success','jy_51job/myitem/main');
		}
	}
	/*
	if((!$member['isvip'] || $member['viptime'] < time()) && $basic['isfee_hongbao']){
		$member['ishongbao'] =0;
	}else{
		$member['ishongbao'] =1;
	}
	*/
	$post['opus_images']=array();
	$post['mobile']=$post['mobile']?$post['mobile']:$member['mobile'];
	$post['name']=$post['name']?$post['name']:$member['nickname'];
	$return['post']=$post;
	$return['list']=$list;
	$return['item_type']=$item_type;
	$return['member']=$member;
	$return['sex']=array('1'=>'男','2'=>'女');
	$return['educationid']=array('1'=>'初中及以下','2'=>'高中、中专','3'=>'大专','4'=>'本科','5'=>'研究生及以上');
	$return['timesid']=array('1'=>'一年以下','2'=>'一至三年','3'=>'三到五年','4'=>'五年以上');
	$return['classifyid']=array('1'=>'电脑办公','2'=>'家具家电','3'=>'手机','4'=>'文体户外','5'=>'服饰配饰','6'=>'儿童母婴','7'=>'美容保健','8'=>'数码产品','9'=>'居家日常','10'=>'其他');
	$return['isbuy']=array('0'=>'求购','1'=>'出售','3'=>'转让');
	$return['lev']=array('1'=>'轿车','2'=>'SUV','3'=>'MPV','4'=>'微面','5'=>'皮卡','6'=>'电动车','7'=>'其他');
	$return['pay']=array('0'=>'面议','1'=>'1-1000','2'=>'1000-2000','3'=>'2000-3000','4'=>'3000-5000','5'=>'5000-8000','6'=>'8000-10000','7'=>'1000-15000','8'=>'15000以上');
	$return['province']=cfc('tools')->pcd();
	$return['os']=$_SESSION['os'];
	exi($return);

}
if($_RQ['op']=='payresult'){
	$payresult=$_RQ['pay_result'];
	if(!$payresult){
		exi('支付失败，未收到支付结果！','error');
	}
	if($payresult['status']!=1){
		exi('支付失败！','error');
	}
	$order=pdo_get('jy_51job_fabulog',array('id'=>$payresult['id'],'uniacid'=>$_SESSION['uniacid']));
	if(!$order){
		exi('支付失败！订单不存在！','error');
	}
	if($order['fee']!=$payresult['fee']){
		exi('支付失败！订单金额不匹配！','error');
	}
	if($basic['item_shenhe']){
		$status=0;
	}else{
		$status=1;
	}
	pdo_update('jy_51job_fabulog',array('status'=>1,'ispay'=>1,'fee'=>$payresult['fee'],'paytime'=>time()),array('id'=>$order['id']));
	pdo_update('jy_51job_job',array('status'=>$status,'ispay'=>1,'fee'=>$payresult['fee']),array('id'=>$order['itemid']));
	exi('发布成功','success','jy_51job/myitem/main');
}
if($_RQ['op']=='getfileds'){
	//查询自定义字段
	$fileds=pdo_getcolumn('jy_51job_reply',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']),'fileds');
	$fileds = json_decode($fileds,true);
	foreach($fileds as &$item){
		$item['value']=explode(';',$item['value']);
	}
	$return['post']=array();
	$return['post']['fileds']=$fileds;
	$return['success']=1;
	exi($return);
}